#include "../Tasks/Task_ADC.h"
#include "../Tasks/Task_USB.h"
#include "bsp_log.h"
#define STACKSIZE_ADC	configMINIMAL_STACK_SIZE
#define PRIORITY_ADC	(tskIDLE_PRIORITY+2)
TaskHandle_t H_Task_ADC;
QueueHandle_t xQueue_ADC;
char buffer[200],num;
char string[16];
uint16_t adc_v11,adc_ch10;
static void Task_ADC(void* param)
{
    uint8_t tempdata[64];
    float voltage;
    bsp_adc_init();
	xQueue_ADC = xQueueCreate(1,sizeof(uint16_t));
    ADC1_Start_convert();
	while(1)
	{	
        ADC1_Start_convert();
		Get_ADC_V11(&adc_v11);
        adc_ch10 = Get_AIN10Data();
		insertdisplaydata(adc_ch10/64);
        voltage = (adc_ch10*1.1)/adc_v11;
		num = sprintf(string,"ADC: %5.4fV ",voltage);
//        tempdata[0] = CMD_USB_Write;
//        tempdata[1] = REG_Voltage;
//        *(float*)(&tempdata[2]) = voltage;
//        bsp_usb_hid_send_report(tempdata,64);
		if(num<10)
		{
			for(int i = 0;i<(10-num);i++)
			{
				string[num+i] = ' ';
			}
			string[10] = '\0';
		}
		OLED_ShowString2(0,0,(unsigned char *)string);
        vTaskDelay(10/portTICK_PERIOD_MS);
	}
}
uint8_t Task_ADC_Start(void)
{
	xTaskCreate(Task_ADC,(const char *)"Display Task",STACKSIZE_ADC,NULL,PRIORITY_ADC,&H_Task_ADC);
	return Ok;
}



